package com.app.teaware.goods;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.app.teaware.R;
import com.app.teaware.basis.BasisActivity;
import com.app.teaware.basis.Constants;
import com.app.teaware.bean.BasisBean;
import com.app.teaware.bean.CompanyListBean;
import com.app.teaware.bean.CraftListBean;
import com.app.teaware.bean.GoodsSubmitData;
import com.app.teaware.bean.GoodsWorkm;
import com.app.teaware.bean.GoodsWorks;
import com.app.teaware.bean.GoodsWorksListBean;
import com.app.teaware.bean.LoginBean;
import com.app.teaware.bean.MenuBean;
import com.app.teaware.bean.WorkListData;
import com.app.teaware.bluetooth.SearchBlueToothActivity;
import com.app.teaware.goods.AddGoodsInfoActivity;
import com.app.teaware.goods.GoodsListActivity;
import com.app.teaware.util.Analysis;
import com.app.teaware.util.BluetoothUtils;
import com.app.teaware.util.MyEvent;
import com.app.teaware.util.MyUtils;
import com.app.teaware.util.UnitUtil;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.flyco.dialog.listener.OnBtnClickL;
import com.google.gson.Gson;
import com.qmuiteam.qmui.skin.QMUISkinManager;
import com.qmuiteam.qmui.widget.dialog.QMUIDialog;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import my.ActivityTool;
import my.DialogUtils;
import my.MathUtils;
import my.TimeUtils;
import my.ViewUtils;
import my.http.MyHttpListener;
import my.http.MyHttpUtils;
import my.http.MyParams;

/***
 * 领料管理-修改
 * **/
public class AddOrEditGoodsActivity extends BasisActivity {

    private int mCurrentDialogStyle = com.qmuiteam.qmui.R.style.QMUI_Dialog;

    @BindView(R.id.recyclerview)
    RecyclerView mRecyclerView;
    MyAdapterList mAdapter;
    
    
    Calendar calendar;

    @BindView(R.id.text_time)
    TextView text_time;
    @BindView(R.id.text_type)
    TextView text_type;
    @BindView(R.id.text_craft)
    TextView text_craft;
    @BindView(R.id.edit_gno)
    EditText edit_gno;
    @BindView(R.id.edit_no)
    EditText edit_no;
    @BindView(R.id.view_customer)
    View view_customer;
    @BindView(R.id.view_tooth_weight)
    View view_tooth_weight;
    @BindView(R.id.text_customer)
    TextView text_customer;
    @BindView(R.id.text_tooth_weight)
    TextView text_tooth_weight;

    @BindView(R.id.edit_weight)
    EditText edit_weight;
    @BindView(R.id.edit_num)
    EditText edit_num;
    @BindView(R.id.edit_status)
    EditText edit_status;
    @BindView(R.id.view_maker)
    View view_maker;
    @BindView(R.id.edit_maker)
    EditText edit_maker;
    @BindView(R.id.view_wbx)
    View view_wbx;
    @BindView(R.id.edit_wbx)
    EditText edit_wbx;
    @BindView(R.id.text_unit)
    TextView text_unit;


    @BindView(R.id.view_scan)
    View view_scan;
    @BindView(R.id.view_craft)
    View view_craft;
    String craftCid;

    GoodsSubmitData submitData;
    GoodsWorkm workm;

    String[] types = null;
    String[] customers = null;
    CompanyListBean companyList;
    CraftListBean craftList;

    WorkListData workListData;    //如果是点击修改进来的  就会带值
    String title;

    IntentFilter mFilter = new IntentFilter("nlscan.action.SCANNER_RESULT");
    public BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final  String scanResult_1 = intent.getStringExtra("SCAN_BARCODE1");
            final  String scanResult_2 = intent.getStringExtra("SCAN_BARCODE2");
            final  int barcodeType = intent.getIntExtra("SCAN_BARCODE_TYPE",-1);
            final String scanStatus = intent.getStringExtra("SCAN_STATE");
            if("ok".equals(scanStatus)){
                edit_gno.setText(scanResult_1.trim());
            }
        }//end onReceiver
    };

    @Override
    public void initViews() {
        // TODO Auto-generated method stub
        super.initViews();
        setContentView(R.layout.add_edit_goods_activity);
        setTitleLeftButton(null);
        submitData = new GoodsSubmitData();
        workm = new GoodsWorkm();
        LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mRecyclerView.setLayoutManager(layoutManager);
        mContext.registerReceiver(mReceiver,mFilter);
        checkBlueTooth();
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.initData(savedInstanceState);
        workListData = (WorkListData) getIntent().getSerializableExtra("bean");
        title = getIntent().getStringExtra("title");
        setTitle(title);
        if(title.equals("修改") && workListData == null){
            finish();
            return;
        }
        init();
        EventBus.getDefault().register(this);
    }

    void checkBlueTooth(){
        int blueToothIcon = BluetoothUtils.getInstance().checkConnect()?R.mipmap.blue_tooth_on:R.mipmap.blue_tooth_off;
        setTitleRightButton(blueToothIcon, new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if(!BluetoothUtils.getInstance().checkConnect()){
                    ActivityTool.skipActivity(mContext, SearchBlueToothActivity.class);
                }
//                else {
//                    BluetoothUtils.getInstance().logout();
//                    checkBlueTooth();
//                }
            }
        });
    }

    void viewShowOrHide(){
        switch (text_type.getText().toString()){
            case "生产":
                view_scan.setVisibility(View.VISIBLE);
                break;
            case "订单":
                view_scan.setVisibility(View.VISIBLE);
                if(companyList.getAllCustomerNames() != null){
                    customers = companyList.getAllCustomerNames();
                    text_customer.setText(customers[0]);
                }
                break;
            case "计划":
                view_scan.setVisibility(View.VISIBLE);
                customers = getResources().getStringArray(R.array.no_customer);
                text_customer.setText(customers[0]);
                break;
            default:
                view_scan.setVisibility(View.GONE);
                break;
        }
    }

    void init(){
        switch (MyUtils.getHomeSelectName()){
            case "加工入库":
                types = getResources().getStringArray(R.array.order_type);
                view_customer.setVisibility(View.VISIBLE);
                view_tooth_weight.setVisibility(View.GONE);

                MenuBean menuBean = LoginBean.getInstance().getMenuBeanByMna(MyUtils.getHomeSelectName());
                if(menuBean == null)return;
                MyParams params = new MyParams();
                params.put("aid",menuBean.getAid());
                params.put("cfsign", "1");
                showLoading();
                MyHttpUtils.get(Constants.URL_COMPANY_SELECT_ALL, params, new MyHttpListener() {
                            @Override
                            public void onSuccess(int httpWhat, Object result) {
                                if(isFinishing()) return;
                                companyList = (CompanyListBean) result;
                                if(title.equals("新增") && companyList != null && companyList.getList().size()>0){
                                        text_customer.setText(companyList.getAllCustomerNames()[0]);
                                }
                                viewShowOrHide();
                            }

                            @Override
                            public void onFailure(int httpWhat, Object result) {
                                super.onFailure(httpWhat, result);

                            }

                            @Override
                            public void onFinish(int httpWhat) {
                                dismissProgress();
                            }
                        },
                        0, CompanyListBean.class);
                break;
            default:            //领料管理-退料管理
                types = getResources().getStringArray(R.array.good_type);
                view_customer.setVisibility(View.GONE);
                break;
        }

        if(title.equals("修改")){
            text_time.setText(workListData.getMdt());
            edit_no.setText(workListData.getMno());
            edit_gno.setText(workListData.getWno());
            edit_status.setText(workListData.getTys());
            edit_maker.setText(workListData.getUno());
            text_type.setText(workListData.getMty());
            text_customer.setText(workListData.getMna());
            text_craft.setText(workListData.getCna());
            craftCid = workListData.getCid();
//            text_tooth_weight.setText(workListData.getWch());   //TODO 反正都要重新获取一遍

            showLoading();
            MyParams params = new MyParams();
            params.put("aid", LoginBean.getInstance().getAcode());
            params.put("tid", workListData.getMid());
            params.put("bfs", MyUtils.getHomeSelectId());
            MyHttpUtils.get(Constants.URL_WORK_GET_WORKS_BY_ID, params, new MyHttpListener() {
                        @Override
                        public void onSuccess(int httpWhat, Object result) {
                            if(isFinishing()) return;
                            GoodsWorksListBean listBean = (GoodsWorksListBean) result;
                            if(listBean.getList()!= null && listBean.getList().size()>0){
                                mRecyclerView.setVisibility(View.VISIBLE);
                                submitData.setWorks(listBean.getList());
                                initDataByWorks();
                            }
                        }

                        @Override
                        public void onFailure(int httpWhat, Object result) {
                            super.onFailure(httpWhat, result);

                        }

                        @Override
                        public void onFinish(int httpWhat) {
                            setListView();
                            hideLoading();
                        }
                    },
                    0, GoodsWorksListBean.class);

        }else if(title.equals("新增")){
            text_type.setText(types[0]);
            text_time.setText(TimeUtils.getCurrentTimeByFormat("yyyy-MM-dd"));
            view_maker.setVisibility(View.GONE);
            showLoading();
            MyParams params = new MyParams();
            params.put("aid", LoginBean.getInstance().getAcode());
            MyHttpUtils.get(Constants.URL_WORL_RERURN_BO_BY_ID, params, new MyHttpListener() {
                        @Override
                        public void onSuccess(int httpWhat, Object result) {
                            if(isFinishing()) return;
                            BasisBean listBean = (BasisBean) result;
                            if(listBean.getResultData()!= null){
                                edit_no.setText(listBean.getResultData());
                            }
                        }

                        @Override
                        public void onFailure(int httpWhat, Object result) {
                            super.onFailure(httpWhat, result);

                        }

                        @Override
                        public void onFinish(int httpWhat) {
                            hideLoading();
                        }
                    },
                    0, BasisBean.class);
        }


        showLoading();
        MyParams params = new MyParams();
        params.put("aid", LoginBean.getInstance().getAcode());
        MyHttpUtils.get(Constants.URL_CRAFT_SELECT_ALL, params, new MyHttpListener() {
                    @Override
                    public void onSuccess(int httpWhat, Object result) {
                        if(isFinishing()) return;
                        craftList = (CraftListBean) result;
                        if(title.equals("新增") && craftList.getAllNames()!=null){
                            text_craft.setText(craftList.getAllNames()[0]);
                            craftCid = craftList.getList().get(0).getCid();
                        }

                    }

                    @Override
                    public void onFailure(int httpWhat, Object result) {
                        super.onFailure(httpWhat, result);

                    }

                    @Override
                    public void onFinish(int httpWhat) {
                        hideLoading();
                    }
                },
                0, CraftListBean.class);

    }

    private void initDataByWorks(){
        if(submitData.getWorks() == null || submitData.getWorks().size()<1){
            edit_weight.setText("");
            edit_num.setText("");
            view_wbx.setVisibility(View.GONE);
        }else {
            edit_weight.setText(""+submitData.getWeight());
            edit_num.setText(""+submitData.getNum());
            if(!MyUtils.getHomeSelectName().equals("加工入库")){
                edit_wbx.setText(submitData.getAllWbx());
                view_wbx.setVisibility(View.VISIBLE);
                text_unit.setVisibility(View.VISIBLE);
            }

        }
    }

    @OnClick(R.id.view_type)
    void typeBtn() {
        if(types == null) return;
        new QMUIDialog.MenuDialogBuilder(mContext)
                .setSkinManager(QMUISkinManager.defaultInstance(mContext))
                .addItems(types, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
//                        showToast("你选择了 " + types[which]);
                        text_type.setText(types[which]);
                        viewShowOrHide();
                        dialog.dismiss();
                    }
                })
                .create(mCurrentDialogStyle).show();
    }

    @OnClick(R.id.view_customer)
    void customBtn() {
        if(customers == null) return;
        new QMUIDialog.MenuDialogBuilder(mContext)
                .setSkinManager(QMUISkinManager.defaultInstance(mContext))
                .addItems(customers, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
//                        showToast("你选择了 " + types[which]);
                        text_customer.setText(customers[which]);
                        dialog.dismiss();
                    }
                })
                .create(mCurrentDialogStyle).show();
    }

    @OnClick(R.id.view_craft)
    void craftBtn() {
        if(craftList.getAllNames() == null) return;
        new QMUIDialog.MenuDialogBuilder(mContext)
                .setSkinManager(QMUISkinManager.defaultInstance(mContext))
                .addItems(craftList.getAllNames(), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
//                        showToast("你选择了 " + types[which]);
                        text_craft.setText(craftList.getAllNames()[which]);
                        craftCid = craftList.getList().get(which).getCid();
                        dialog.dismiss();
                    }
                })
                .create(mCurrentDialogStyle).show();
    }

    @OnClick(R.id.view_time)
    void viewTime(){
        //时间选择器
        TimePickerView pvTime = new TimePickerBuilder(mContext, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                if (calendar == null) {
                    calendar = Calendar.getInstance();
                }
                calendar.setTime(date);
                onTimeChoosed();
            }
        })
                .addOnCancelClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                    }
                })
                .setType(new boolean[]{true, true, true, false, false, false})// 默认全部显示
                .build();
        pvTime.show();
        ViewUtils.hideInput(mContext);
    }

    void onTimeChoosed() {
        text_time.setText(calendar == null? "": TimeUtils.getTimeByDate(calendar.getTime(), "yyyy-MM-dd"));
    }

    @OnClick(R.id.btn_add)
    void btnAdd(){
        if(TextUtils.isEmpty(edit_no.getText().toString())){
            showToast("单号不能为空");
            return;
        }
        AddGoodsInfoActivity.toDetail(AddOrEditGoodsActivity.this,edit_no.getText().toString(),craftCid,Constants.SCANDATASULT);
    }

    @OnClick(R.id.btn_submit)
    void checkSubmit(){

        if(text_type.getText().toString().equals("生产") ){
            if(TextUtils.isEmpty(edit_gno.getText().toString())){
                showToast("工单号不可为空");
                return;
            }
        }

        if(TextUtils.isEmpty(edit_no.getText().toString())){
            showToast("单号不可为空");
            return;
        }

        if(TextUtils.isEmpty(text_tooth_weight.getText().toString()) && !MyUtils.getHomeSelectName().equals("加工入库")){
            showToast("请先通过蓝牙获取重量");
            return;
        }

        if(submitData.getWorks() == null || submitData.getWorks().size()<1){
            showToast("请点击最下方入库资料按钮，添加子表");
            return;
        }

        if(TextUtils.isEmpty(edit_num.getText().toString())){
            showToast("数量不能为空");
            return;
        }


        if(MyUtils.getHomeSelectName().equals("加工入库")){
            btnsubmit();
            return;
        }

         String wcz = submitData.getMinWcz(); //误差值
        String trueWeight = MathUtils.subtract(text_tooth_weight.getText().toString(),edit_wbx.getText().toString());
        int isMoreWeight = MathUtils.compareTo(trueWeight,edit_weight.getText().toString());

//        isMoreWeight == -1,表示bg1小于bg2；
//		isMoreWeight == 0,表示bg1等于bg2；
//		isMoreWeight == 1,表示bg1大于bg2；

        switch (isMoreWeight){
            case -1:
                String cyz/*差异值*/ = MathUtils.subtract(edit_weight.getText().toString(),trueWeight);   //箱子的重量 减去  trueWeight（蓝牙称重 - 箱体的重量）
               int a = MathUtils.compareTo(cyz,String.valueOf(wcz));
               if(a == 1){
                   BluetoothUtils.getInstance().startWarning();
                   DialogUtils.DialogOne(mContext, "提示", "重量不足！", "知道了", new OnBtnClickL() {
                       @Override
                       public void onBtnClick() {
                           BluetoothUtils.getInstance().stopWarning();
                       }
                   });
               }else {
                   btnsubmit();
               }
                break;
            case 0:
                btnsubmit();
                break;
            case 1:
                BluetoothUtils.getInstance().startWarning();
                DialogUtils.DialogOne(mContext, "提示", "重量超重！", "知道了", new OnBtnClickL() {
                    @Override
                    public void onBtnClick() {
                        BluetoothUtils.getInstance().stopWarning();
                    }
                });

                break;
        }

    }
    void btnsubmit(){
        workm.setAid(LoginBean.getInstance().getAcode());
        workm.setBfs(MyUtils.getHomeSelectId());
        workm.setUno(LoginBean.getInstance().getUname());
        if(text_type.getText().toString().equals("生产")){
            workm.setCna(text_craft.getText().toString());
        }
        workm.setCid(craftCid);
        workm.setMdt(text_time.getText().toString());
        if(title.equals("修改")){
            workm.setMid(workListData.getMid());        //新增不用
        }
        workm.setWno(edit_gno.getText().toString());
        workm.setMty(text_type.getText().toString());
        workm.setMno(edit_no.getText().toString());

        if(MyUtils.getHomeSelectName().equals("加工入库")){
            workm.setMna(text_customer.getText().toString());
        }else {
            workm.setWch(text_tooth_weight.getText().toString());
        }
        submitData.setWorkm(workm);

        MyParams params = new MyParams();
        showProgress();
        Gson gson = new Gson();
        String a = gson.toJson(submitData);
        params.putJson(a);

        MyHttpUtils.postJson(Constants.URL_WORK_INSERT, params, new MyHttpListener() {
                    @Override
                    public void onSuccess(int httpWhat, Object result) {
                        if(isFinishing()) return;
                        BasisBean basisBean = (BasisBean) result;
                        showToast(((BasisBean) result).getStatusInfo());
                        setResult(GoodsListActivity.WARNLISTRESULT);
                        dismissProgress();
                        finish();
                    }

                    @Override
                    public void onFailure(int httpWhat, Object result) {
                        dismissProgress();
                        super.onFailure(httpWhat, result);
                    }

                    @Override
                    public void onFinish(int httpWhat) {

                    }
                },
                0, BasisBean.class);

    }

    @OnClick(R.id.view_tooth_weight)
    void getWeightByBlueTooth(){
        if(!BluetoothUtils.getInstance().checkConnect()){
            checkBlueTooth();
            showToast("请点击右上角蓝牙按钮，匹配相关设备");
            return;
        }

        BluetoothUtils.getInstance().sendAndNotify(Analysis.getBytes("R"), new BluetoothUtils.MySendListener() {
            @Override
            public void onFailure(String message) {
                showToast(message);
            }

            @Override
            public void onSuccess(String result) {
//                String a ="+  0.081 kg";
                String a =result;
                String unit =  UnitUtil.getUnitByString(a);
                workm.setWun(unit);
                String weight = UnitUtil.getNumByString(a);

                double cz = UnitUtil.getRatio(unit,"g");
                weight = MathUtils.multiply(weight,String.valueOf(cz));
                text_tooth_weight.setText(weight);

            }

            public void onTimeout() {
                showToast("超时");

            }
        });
    }

    private void setListView() {
        if (mAdapter == null) {
            mAdapter = new MyAdapterList();
            mAdapter.notifyDataSetChanged();
            mRecyclerView.setAdapter(mAdapter);
        } else {
            mAdapter.notifyDataSetChanged();
        }
        initDataByWorks();
    }

    public class MyAdapterList extends RecyclerView.Adapter<MyAdapterList.ViewHolder> {

        public MyAdapterList() {

        }

        //创建新View，被LayoutManager所调用
        @Override
        public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
            View view = LayoutInflater.from(mContext).inflate(R.layout.goods_info_list_item, viewGroup, false);
            return new ViewHolder(view);
        }


        //将数据与界面进行绑定的操作
        @Override
        public void onBindViewHolder(ViewHolder viewHolder, int position) {
            viewHolder.bind(position);
        }

        //获取数据的数量
        @Override
        public int getItemCount() {
            return submitData == null ? 0 : submitData.getWorks().size();
        }

        //自定义的ViewHolder，持有每个Item的的所有界面元素
        public class ViewHolder extends RecyclerView.ViewHolder {
            @BindView(R.id.text_code)
            public TextView text_code;
            @BindView(R.id.text_name)
            public TextView text_name;
            @BindView(R.id.text_specs)
            public TextView text_specs;
            @BindView(R.id.text_price)
            public TextView text_price;
            @BindView(R.id.text_num)
            public TextView text_num;
            @BindView(R.id.text_weight)
            public TextView text_weight;
            @BindView(R.id.text_kw)
            public TextView text_kw;
            @BindView(R.id.text_qrcode)
            public TextView text_qrcode;
            @BindView(R.id.btn_delete)
            public TextView btn_delete;
            @BindView(R.id.btn_edit)
            public TextView btn_edit;

            public ViewHolder(View view) {
                super(view);
                ButterKnife.bind(this, view);
            }

            public void bind(int position) {
                GoodsWorks data = submitData.getWorks().get(position);
                text_code.setText(data.getGno());
                text_name.setText(data.getGna());
                text_specs.setText(data.getGsp());
                text_price.setText(""+data.getGun());
                text_num.setText(data.getGnu());
                text_weight.setText(""+data.getGwt());
                text_kw.setText(data.getWms());
                text_qrcode.setText(data.getRfid());

                btn_delete.setTag(position);
                btn_edit.setTag(position);
            }

            @OnClick(R.id.btn_delete)
            public void onItemDelClick(View v) {
                int position = (int) v.getTag();
                List<GoodsWorks> a = submitData.getWorks();
                a.remove(position);
                setListView();
            }
            @OnClick(R.id.btn_edit)
            public void onItemEditClick(View v) {
                int position = (int) v.getTag();
                GoodsWorks goodsWork = submitData.getWorks().get(position);
                AddGoodsInfoActivity.toEdit(AddOrEditGoodsActivity.this,edit_no.getText().toString(),craftCid,goodsWork,Constants.SCANDATASULT);
            }

        }
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(resultCode == Constants.SCANDATASULT){
            ArrayList<GoodsWorks> worksList = (ArrayList<GoodsWorks>) data.getSerializableExtra("list");
            if(submitData.getWorks() == null || submitData.getWorks().size()<0){
                submitData.setWorks(worksList);
            }else {
                if(worksList != null){
                    for (GoodsWorks childBean : worksList){
                        boolean isHave = false;
                        for(int i = 0;i<submitData.getWorks().size();i++){
                            GoodsWorks paramBean = submitData.getWorks().get(i);
                            if(childBean.getRfid().equals(paramBean.getRfid())){
                                submitData.getWorks().set(i,childBean);
                                isHave = true;
                            }
                        }
                        if(!isHave){
                            submitData.getWorks().add(childBean);
                        }
                    }
                }
            }
            mRecyclerView.setVisibility(View.VISIBLE);
            setListView();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        mContext.registerReceiver(mReceiver,mFilter);
        checkBlueTooth();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mContext.unregisterReceiver(mReceiver);
        EventBus.getDefault().unregister(this);
    }


    @Subscribe
    public void onEventGet(MyEvent event) {
        checkBlueTooth();
        if (event.getType() == MyEvent.EVENT_TYPE_DISCONNECT) {
            BluetoothUtils.getInstance().showReconnectDialog(mContext);
        }else if (event.getType() == MyEvent.EVENT_TYPE_CONNECT) {
            checkBlueTooth();
        }
    }
}
